package com.hualan.dao.impl;

import com.hualan.bean.PanghuShop;
import com.hualan.dao.StoreDaoAdd;
import com.hualan.utils.DruidUtil;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

public class StoreDaoAddImpl implements StoreDaoAdd {
    //新增,插入数据
    @Override
    public int insert(PanghuShop entity) {
        int row = DruidUtil.update("insert into panghu_shop(shop_name, shop_describe, shop_image, shop_phone, shop_province, shop_city, shop_district, shop_address, shop_longitude, shop_latitude) values(?,?,?,?,?,?,?,?,?,?)",entity.getShopName(),entity.getShopDescribe(),entity.getShopImage(),entity.getShopPhone(),entity.getShopProvince(),entity.getShopCity(),entity.getShopDistrict(),entity.getShopAddress(),entity.getShopLongitude(),entity.getShopLatitude());

        return row;
    }

    //删除数据
    @Override
    public int delete(Integer id) throws SQLException {
        int row = DruidUtil.update("delete from panghu_shop", id);
        return row;
    }

    //编辑,修改数据
    @Override
    public int update(PanghuShop entity) {
        int row = DruidUtil.update("update panghu_shop set shop_name = ?,shop_describe = ?,shop_image = ?,shop_phone = ?,shop_province = ?,shop_city = ?,shop_district = ?,shop_address = ?,shop_longitude = ?,shop_latitude = ? where shop_id = ?",entity.getShopName(),entity.getShopDescribe(),entity.getShopImage(),entity.getShopPhone(),entity.getShopProvince(),entity.getShopCity(),entity.getShopDistrict(),entity.getShopAddress(),entity.getShopLongitude(),entity.getShopLatitude(),entity.getShopId());
//        System.out.println("dao层里面的id:" + entity.getShopId());
        return row;
    }

    //按id查询
    @Override
    public PanghuShop selectById(Integer id) {
        PanghuShop panghuShop = DruidUtil.queryOne("select * from panghu_shop where shop_id = ?", PanghuShop.class, id);
        return panghuShop;
    }

    //分页查询
    @Override
    public List<PanghuShop> selectByPage(Integer pageNum, Integer pageSize) {
        List<PanghuShop> shopList = DruidUtil.query("select * from panghu_shop limit ?,?",PanghuShop.class,(pageNum-1) * pageSize,pageSize);

        return shopList;
    }

    //查询所有
    @Override
    public long selectAll() {
        Map<String, Object> map = DruidUtil.queryOne("select count(*) as count from panghu_shop");
        Long count = (Long) map.get("count");
        return count;
    }
}

